package com.tencent.qcloud.timchat.utils;

import android.content.Context;
import android.graphics.drawable.AnimationDrawable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.wbao.dianniu.R;


/**
 * 发送语音提示控件
 */
public class VoiceSendingView extends RelativeLayout {


    private AnimationDrawable frameAnimation;
    private TextView cancelTV;
    private Context mContext;
    private ImageView img;

    public VoiceSendingView(Context context, AttributeSet attrs) {
        super(context, attrs);
        mContext = context;
        LayoutInflater.from(context).inflate(R.layout.voice_sending, this);
        img = (ImageView) findViewById(R.id.microphone);
        cancelTV = (TextView) findViewById(R.id.cancel_voice_tv);
        img.setBackgroundResource(R.drawable.animation_voice);
        frameAnimation = (AnimationDrawable) img.getBackground();

    }

    public void showRecording() {
        cancelTV.setText(mContext.getResources().getString(R.string.chat_up_finger));
        cancelTV.setTextColor(getResources().getColor(R.color.white));
        img.setBackgroundResource(R.drawable.animation_voice);
        frameAnimation = (AnimationDrawable) img.getBackground();
        frameAnimation.start();
    }

    public void showCancel() {
        frameAnimation.stop();
    }

    public void release() {
        frameAnimation.stop();
    }


    public void unpressVoice() {
        cancelTV.setText(mContext.getResources().getString(R.string.unpress_cancel_voice));
        cancelTV.setTextColor(getResources().getColor(R.color.red));
        img.setBackgroundResource(R.drawable.cancel_voice);
        frameAnimation.stop();
    }

    public void recoveryVoice() {
        cancelTV.setText(mContext.getResources().getString(R.string.chat_up_finger));
        cancelTV.setTextColor(getResources().getColor(R.color.white));
        img.setBackgroundResource(R.drawable.animation_voice);
        frameAnimation = (AnimationDrawable) img.getBackground();
        frameAnimation.start();
    }

}
